//****************************************************************************
//
// main.c - General scheduler
//
//****************************************************************************

#include "inc/hw_types.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "utils/scheduler.h"
#include "driverlib/interrupt.h"

#include "drive_task.h"
#include "auto_task.h"
#include "distanceIR_task.h"
#include "wireless_task.h"
#include "helper.h"


//*****************************************************************************
// The error routine that is called if the driver library encounters an error.
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
    UARTprintf("DriverLib assertion error in %s@%d\n", pcFilename, ulLine);
    for(;;)
    {
    }
}
#endif

//*****************************************************************************
// The Scheduler task table.  This table holds function pointers to all the
// tasks that will be called by the simple scheduler, along with the periodic
// timeout value.
//*****************************************************************************
tSchedulerTask g_psSchedulerTable[] =
{
    { DistanceIRTask, 0, 15, 0, true },
    { AutoTask, 0, 0, 0, true },
    { WirelessTask, 0, 1, 0, true},
};

//*****************************************************************************
// The number of entries in the global scheduler task table.
//*****************************************************************************
unsigned long g_ulSchedulerNumTasks = (sizeof(g_psSchedulerTable) / sizeof(tSchedulerTask));

//*****************************************************************************
// The main entry point for the leader.
//*****************************************************************************
int main (void)
{
    // Set the system clock to run at 50MHz from the PLL
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // Initialize the simple scheduler to use a tick rate of 100 Hz.
    SchedulerInit(2500);

    // Initialize all the tasks used in the example.
    DriveInit();
    HelperDisplayInit();
    AutoTaskInit();
    DistanceIRTaskInit();

    WirelessInit();
    FollowerLink();

	IntMasterEnable();

    // Enter a forever loop and call the scheduler.  The scheduler will
    // periodically call all the tasks in the system according to the timeout
    // value of each task.
    while(true)
    {
    	SchedulerRun();
    }
}
